package tencent.d20210904.t1;


/**
 * @author habitplus
 * @since 2021-09-05 19:49
 */
public class Main {
    private class ListNode {
        int val;
        ListNode next = null;
        public ListNode(int val) {
            this.val = val;
        }
    }

    public ListNode solve (ListNode[] a) {
        // write code here
        if (a == null || a.length == 0) {
            return null;
        }

        ListNode tou = new ListNode(0);
        ListNode ass = tou;
        ListNode t;
        boolean hasNode = true;
        while (hasNode) {
            hasNode = false;
            for (int i = 0; i < a.length; i++) {
                if (a[i] != null) {
                    t = a[i].next;
//                    a[i].next = null;
                    ass.next = a[i];
                    ass = a[i];
                    a[i] = t;
                    hasNode = true;
                }
            }
        }
        ass.next = null;

        return tou.next;
    }
}
